import { defineComponent, reactive, ref } from "vue";
import LForm, { LFormItem } from "@/components/public/lForm/lForm";
import styles from "./addinsure.module.less";
import { message } from "ant-design-vue";
import LPopup from "@/components/public/lPopup/lPopup";
import {
  $orderInsuranceDoInsure,
} from "@/api/orderInsurance/orderInsurance";
export default defineComponent({
  props: {
    service: {
      type: Object,
      required: true,
    },
  },
  emits: ["cancel", "confirm"],
  setup(props, { emit, expose }) {
    const state = reactive({
      order_no:"",
      insurance_order_no:"",
    } as any);

    const cancelHandler = () => {
      addPopupRef.value.close();
    };
    const confirmHandler = (e: any) => {
      $orderInsuranceDoInsure(e.form).then((res:any)=>{
        message.success("承保成功");
        emit("confirm");
      }).finally(() => {
        e.done();
      });
    };

    const addPopupRef = ref(null as any);
    const open = (e:any) => {
        state.order_no = e;
        state.insurance_order_no = "";
       addPopupRef.value.open();
    };
    const close = () => {
      addPopupRef.value.close();
    };

    expose({
      open,
      close,
    });
    const Components = () => (
      <LPopup title="承保信息" ref={addPopupRef}>
        <div class={styles.addInsureBox}>
          <div class={styles.addInsureBodyBox}>
            <LForm
              btns={["cancel", "confirm"]}
              v-model={state}
              rules={state.rules}
              onCancel={() => {
                cancelHandler();
              }}
              onConfirm={(e: any) => {
                confirmHandler(e);
              }}
            >
              <LFormItem label="保司保单号:" prop="">
                <a-input
                  v-model:value={state.insurance_order_no}
                  placeholder="请输入保司保单号"
                ></a-input>
              </LFormItem>
             
            </LForm>
          </div>
        </div>
      </LPopup>
    );
    return {
      Components,
    };
  },
  render() {
    return <this.Components />;
  },
});